﻿using System;
using System.Linq;
using Algorithm;
using Framework.Game;
using Game.Config;
using Game.Input;
using UnityEngine;
using UnityEngine.PlayerLoop;
using UnityEngine.SceneManagement;

namespace Game
{
    public class GameRoot : MonoBehaviour
    {
        [SerializeField]
        public GlobalConfig globalConfig;

        private GameManager m_gameMgr;

        private void OnEnable()
        {
            GameObject.DontDestroyOnLoad(gameObject);
            // 初始化游戏管理器
            m_gameMgr = GameManager.instance;
            Debug.Log("输出初始化" + m_gameMgr);
            m_gameMgr.Init(globalConfig);
            
            
            var sort = new QuickSort();
            var sortArray = new int[]{1,9,2,3,5,7,3,2,1,3,4,5,1};
            Debug.Log("排序之前 " + PrintArray(sortArray));
            sort.SortArray(ref sortArray);
            
            string PrintArray(int[] printArray)
            {
                var a = "";
                for (var i = 0; i < printArray.Length; i++)
                {
                    a += printArray[i] + "->";
                }
            
                return a;
            }
            
            
            
            Debug.Log("排序素组 " + PrintArray(sortArray));
            
        }


        private void Update()
        {
            m_gameMgr.Update(UnityEngine.Time.deltaTime);
        }

        public void TestButton()
        {
            PanelTestView.Load<PanelTestView>();
            
        }
    }
}